﻿var loadingDiv
var etlVars = {};
$(initPage);
function initPage() {
    //30秒自动刷新
	var timer=setTimeout(function(){
		location.reload();
	}, 60000);
	loadingDiv = $("<div style='display:none'><div style='width:100%;z-index:101;height:100%;background-color:#ccc;filter:alpha(Opacity=20);-moz-opacity:0.2;opacity: 0.2;position:absolute;top:0px;left:0px;'></div></div>").appendTo(jQuery(document.body));
	$("<div style='position:absolute;z-index:9999999;border:1px solid #eee;padding:20px 0 0 20px;width:390px;height:48px'/>").css({left:document.body.clientWidth/2-200,top:document.body.clientHeight/2-80}).append("<img width='200' height='15' src='" + BASE_PATH + "themes/comm/images/loading.gif' align='absmiddle'/>&nbsp;<font style='font-size:18px;color:#f30'>数据预处理中……</font>").appendTo(loadingDiv);

	etlVars.etlProcID1 = $("#etlProcID1").val();
	etlVars.procStatus1 = $("#procStatus1").val();
	etlVars.busiDate1 = $("#busiDate1").val();
	
	etlVars.etlProcID2 = $("#etlProcID2").val();
	etlVars.procStatus2 = $("#procStatus2").val();
	etlVars.busiDate2 = $("#busiDate2").val();
	
	etlVars.etlProcID3 = $("#etlProcID3").val();
	etlVars.procStatus3 = $("#procStatus3").val();
	etlVars.busiDate3 = $("#busiDate3").val();
	
	//alert(etlVars.etlProcID1 + " " + etlVars.procStatus1 + " " + etlVars.busiDate1);
	//alert(etlVars.etlProcID2 + " " + etlVars.procStatus2 + " " + etlVars.busiDate2);
	//alert(etlVars.etlProcID3 + " " + etlVars.procStatus3 + " " + etlVars.busiDate3);
	initPreClearInfo();
	
	//生成数据
	$("#preclear").click(function() {
		var busiDate = $("#busiDate").val();
		$("#preclear").attr("disabled", true);//不允许再次操作
		if (etlVars.procStatus1 == "1"){
			alert("股份数据采集运行中，请稍后再试！");
			$("#preclear").attr("disabled", false);//允许再次操作
			return;
		}
		if (etlVars.procStatus2 == "1"){
			alert("股份数据预处理运行中，请稍后再试！");
			$("#preclear").attr("disabled", false);//允许再次操作
			return;
		}
		if (etlVars.procStatus3 == "1"){
			alert("股份数据核对运行中，请稍后再试！");
			$("#preclear").attr("disabled", false);//允许再次操作
			return;
		}
  		if (etlVars.procStatus1 != "2" && !confirm(etlVars.busiDate1 + "：" + procDesc(etlVars.etlProcID1) + "：" + procStatus(etlVars.procStatus1) + "\n股份数据未正常抽取，是否预处理股份数据？")) {
			$("#preclear").attr("disabled", false);//允许再次操作
			return;
		} else if (etlVars.procStatus2 == "2" && !confirm(etlVars.busiDate2 + "：" + procDesc(etlVars.etlProcID2) + "：" + procStatus(etlVars.procStatus2) + "\n股份数据已正常预处理，是否重新预处理股份数据？")) {
			$("#preclear").attr("disabled", false);//允许再次操作
			return;
		}
		
		var taskInfo = busiDate + ":   ";
		taskInfo = taskInfo + "股份数据预处理已开始，请耐心等待。";
		$("#taskInfo").html(taskInfo);
		
		loadingDiv.show();	
		//sjsdz
		$.post("m/stock_chk/preclear", {
			stockProc:"preclear",
			busiDate:busiDate,
            exchangeType : $$("exchangeType").value,
		    srcFlag : $$("srcFlag").value
		}, function(data) {
			loadingDiv.hide();
			$("#preclear").attr("disabled", false);//允许再次操作
			if ($.checkErrorMsg(data) ) {
				alert(data.msg.text);
			} 
			location.reload();
		}, "json");
	});
}

//etlVars.jobStatus 本步骤任务状态：-2未就绪；-1等待；0运行中；1结束；2结束但TS处于运行中;3结束但出错
function initPreClearInfo() {
	//信息内容
	var busiDate = $("#busiDate").val();
	var taskInfo = busiDate + ":   ";
	if (etlVars.procStatus2 == '1') {
		taskInfo = taskInfo + "股份数据预处理已开始，请耐心等待。";
	} else if  (etlVars.procStatus2 == '2') {
		taskInfo = taskInfo + "股份数据预处理已成功完成。";
	} else if  (etlVars.procStatus2 == '3') {
		taskInfo = taskInfo + "股份数据预处理已完成，但有警告发生。";
	} else if  (etlVars.procStatus2 == '9') {
		taskInfo = taskInfo + "股份数据预处理已完成，但有错误发生。";
	} else if  (etlVars.procStatus2 == '0') {
		taskInfo = taskInfo + "股份数据未预处理。";
	} 
	$("#taskInfo").html(taskInfo);
	
	if (etlVars.procStatus2 == '1'){
		loadingDiv.show();	
	}
}
function procDesc(etlProcID){
	var desc = "";
	if (etlProcID == "1"){
		desc = "股份数据采集";
	} else if (etlProcID == "2"){
		desc = "股份数据预处理";
	} else if (etlProcID == "3"){
		desc = "股份数据核对";
    } else if (etlProcID == "4"){
		desc = "股份数据归档";
	}
	return desc;
}
function procStatus(status){
	var desc = "";
	if (status == "0"){
		desc = "未处理";
	} else if (status == "1"){
		desc = "运行中";
	} else if (status == "2"){
		desc = "正常结束";
	} else if (status == "3"){
		desc = "警告结束";
	} else if (status == "9"){
		desc = "错误结束";
	}
	return desc;
}